<% @page_title = "Phishing Templates" %>

<div class='page-header'>
  <h2>Templates</h2>
</div>

<div id="template-buttons">
  <button class="btn btn-default" data-toggle="modal" data-target="#createTemplate">
    Create
  </button>
  <button class="btn btn-default" data-toggle="modal" data-target="#restoreTemplate">
    Restore
  </button>
</div>

<table id="templates" class="table table-striped table-hover table-condensed">
  <thead>
    <tr class="header">
      <th></th>
      <th>Name</th>
      <th>Owner</th>
      <th>Index</th>
      <th>Actions</th>
    </tr>
  </thead>
  <tbody>
    <% @templates.each do |template| %>
    <tr>
      <td><%= template.decorate.template_icon %></td>      
      <td><%= template.name %></td>
      <td><%= template.decorate.owner %></td>
      <td><%= template.index_file %></td>
      <td class="actions">
        <%= link_to(template.decorate.edit_icon,
              {:action => 'edit', :id => template.id}, data: {placement: 'bottom'},
              class: 'btn btn-primary btn-xs', rel: 'tooltip', title: 'Edit Template') %>
        <%= link_to(template.decorate.options_icon,
              {:action => 'show', :id => template.id}, data: {placement: 'bottom'},
              class: 'btn btn-default btn-xs', rel: 'tooltip', title: 'Show Template') %>
        <%= link_to("<span class='glyphicon glyphicon-retweet'></span>".html_safe,
              {:action => 'copy', :id => template.id}, data: {placement: 'bottom'},
              class: 'btn btn-default btn-xs', rel: 'tooltip', title: 'Copy Template', id: 'copy') %>
        <%= link_to("<span class='glyphicon glyphicon-download-alt'></span>".html_safe,
              {:action => 'backup', :id => template.id}, data: {placement: 'bottom'},
              class: 'btn btn-default btn-xs', rel: 'tooltip', title: 'Backup Template') %>
        <%= link_to "<span class='glyphicon glyphicon-remove'></span>".html_safe, 
              template_path(template), method: :delete,
              class: 'btn btn-danger btn-xs', rel: 'tooltip', id: 'delete',
              data: {confirm: 'Are you sure you want to permanently delete this campaign?', placement: 'bottom'}, title: 'Delete Template' %>
      </td>
    </tr>
    <% end %>
  </tbody>
</table>

<!-- Create Template Modal -->
<div class="modal fade" id="createTemplate" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Create Phishing Template</h4>
      </div>
      <div class="modal-body">
        <%= render partial: "new" %>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

<!-- Restore Template Modal -->
<div class="modal fade" id="restoreTemplate" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Restore Phishing Template</h4>
      </div>
      <div class="modal-body">
        <%= render partial: "restore" %>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>
